package se.webbzon.oschi01.main;

import java.io.File;
import java.io.IOException;

import se.webbzon.oschi01.gui.MainFrame;
import se.webbzon.oschi01.gui.MainModel;
import se.webbzon.oschi01.singleton.Singletons;
import se.webbzon.oschi01.world.FileWorld;

public class Main {

	public static void main(String[] args) {
		/*RegionReader reader = Singletons.instance(RegionReader.class);
		RegionReference ref;
		try {
			File file = new File("C:\\temp\\destination\\DIM-1\\region\\r.-1.-1.mca");
			ref = new RegionReference(file.toURI().toURL());
			URLRegion region = reader.read(ref);
			for (int i = 0; i < region.chunks(); i++) try {
				region.getChunk(i).getRoot();
			} catch (NBTException e) {
				e.printStackTrace();
			}
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		System.exit(0);*/
		/*String s1 = "mods.natura.blocks.nether.HeatSand";
		String s2 = "net.minecraft.block.BlockSand";
		String s3 = "net.minecraft.blocks.nether.Sand";
		//String s1 = "mods.natura.blocks.nether.HeatSand";
		ClassNameMetric m = new ClassNameMetric(new JaroWinklerMetric(false));
		System.out.println(m.distance(s1, s2));
		System.out.println(m.distance(s1, s3));
		System.exit(0);*/
		/*Chunk chunk = new DefaultChunk(Singletons.instance(CompoundTagFactory.class).createTag(""),0);
		try {
			System.out.println(chunk.getCoordinate());
			chunk.setCoordinate(2, 3);
			printTagTree(chunk.getRoot(),0);
			chunk.setCoordinate(5, 6);
			printTagTree(chunk.getRoot(),0);
			Tag<Integer> ti = (Tag<Integer>) chunk.getRoot().getChildren().getSibling(0).getChildren().getSibling(0);
			ti.setValue(7);
			printTagTree(chunk.getRoot(),0);
			System.out.println(chunk.getCoordinate());
		} catch (NBTException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		System.exit(0);*/
		if (args.length > 0) {
			File worldFile = new File(args[0]);
			if (worldFile.exists()) {
				try {
					FileWorld world = new FileWorld(worldFile);
					MainModel model = Singletons.instance(MainFrame.class).getModel();
					model.setWorld(world);
					Singletons.instance(MainFrame.class).setVisible(true);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
	
	/*private static void printTagTree(Tag<?> tag, int level) {
		for (int i = 0; i < level; i++)
			System.out.print(" ");
		System.out.println(tag + " = " + tag.getValue());
		if (tag.hasChildren()) {
			for (Tag<?> child : tag.getChildren())
				printTagTree(child,level+1);
		}
	}*/
	
}


